﻿angular.module('Caltech').directive('userDropdown', function (Restangular) {
    'use strict';

    return {
        restrict: 'A',
        //replace: true,
        scope: {
            model: '=bind',
            userDropdown: '@'
        },
        template: '<a href="#" e-typeahead="user as user.name for user in getUserList($viewValue)" e-typeahead-editable="false"' +
                   'editable-text="model" buttons="no" blur="submit">{{model.name}}</a>',
        link: function ($scope, element, attrs) {

            $scope.getUserList = function (name) {
                return Restangular.all('user').getList({
                    fullName: name,
                    role: $scope.userDropdown,
                    compact: true
                });
            };
        }
    }
});
